package com.ruoyi.web.controller.doctor;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.doctor.domain.DoctorPatient;
import com.ruoyi.doctor.domain.DoctorPatientHistory;
import com.ruoyi.doctor.service.DoctorVisitsService;
import com.ruoyi.pssd.domain.PsdDrug;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/Doctor/visits")
public class DoctorVisitsController extends BaseController {

    @Autowired
    DoctorVisitsService service;

    //查询全部
    @PreAuthorize("@ss.hasPermi('system:visits:list')")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        //System.out.println("我是check");
        startPage();
        List<DoctorPatient> doctorPatients = service.queryPatient();
        //System.out.println(sysChecks);
        return getDataTable(doctorPatients);
    }


    //根据患者id查询数据
    @GetMapping("/findPatient")
    public AjaxResult findPatient(int patientId)
    {
        System.out.println(patientId);
        DoctorPatient doctorPatient = service.queryById(patientId);
        return AjaxResult.success(doctorPatient);
    }

    //根据患者id查询数据
    @PostMapping("/add/{historyPatientId}")
    public String addCase(DoctorPatientHistory patientHistory,@PathVariable int historyPatientId)
    {
        System.out.println("patientHistory = " + patientHistory + ", historyPatientId = " + historyPatientId);

        return service.addPatient(patientHistory, historyPatientId);
    }

    //添加药品
    @PostMapping("/addDrug/{patientId}/{drug}/{num}")
    //@Validated 可以和客户端名字保持一直，后台名字可以不一致  @RequestBody 接收客户端的请求体数据
    public int test (@PathVariable int[] drug,@PathVariable int[] num,@PathVariable Integer patientId)
    {
        /*System.out.println(Arrays.toString(drug));
        System.out.println(Arrays.toString(num));
        System.out.println(patientId);
        System.out.println("drug = " + Arrays.toString(drug) + ", num = " + Arrays.toString(num) + ", patientId = " + patientId);
        for (int i = 0; i < drug.length; i++) {
            System.out.println("药品名称"+drug[i]+":"+"药品数量"+num[i]);
        }*/

        int i = service.addDrug(patientId, drug, num);
        if(i != 0){
            return i;
        }
        return 0;
        //System.out.println("patientHistory = " + list + ", historyPatientId = " + patientId);

    }

    //添加检查项
    @PostMapping("/addCheck/{patientId}/{list}")
    public int test (@PathVariable int[] list,@PathVariable Integer patientId){
        return service.addCheck(patientId, list);
    }

    @GetMapping("/succeed")
    public int test (int patientId ){
        System.out.println(patientId);
        return service.updateStatus(patientId);
    }

}
